import { request } from '../http';

export function getMaintenanceInfo() {
  return request.post('/car/index/getMaintenanceInfo');
}

export function bannerList() {
  return request.post('/car/index/getBanner');
}

export function getHelp() {
  return request.post('/car/index/getHelp');
}

export function getDateTimeList() {
  return request.post('/car/index/getOrderDateTime');
}

type AddressListPayload = {
  pagination: boolean;
  page: number;
  pageSize: number;
  typeId: number;
  keyword: string;
};

export function getAddressList(payload: AddressListPayload) {
  return request.post('/car/index/getAddressList',payload);
}

type ServiceListPayload = {
  serviceType: string;
  startAddressId: number;
  endAddressId: number;
  bookDate: string;
  bookTime: string;
};

export function getServiceList(payload: ServiceListPayload) {
  return request.post('/car/service/getList',payload);
}

type createPreOrderPayload = {
  orderType: string;
  serviceType: string;
  startAddressId: number;
  endAddressId: number;
  serviceId: number;
  bookDate: string;
  bookTime: string;
  adultNum: number;
  childNum: number;
};

export function createPreOrder(payload: createPreOrderPayload) {
  return request.post('/car/order/createPreOrder',payload);
}

export function getPreOrderDetail(preOrderSn: string) {
  return request.post('/car/order/getPreOrderDetail', {preOrderSn});
}

export function orderCouponList(preOrderSn: string) {
  return request.post('/car/order/orderCouponList', {preOrderSn});
}


type changePrePayInfoPayload = {
  preOrderSn: string;
  isPickUpSign: boolean;
  childrenSeatAddNum: number;
  extraPackageNum: number;
  couponId: number;
  isBalance: boolean;
};

export function changePrePayInfo(payload: changePrePayInfoPayload) {
  return request.post('/car/order/changePrePayInfo',payload);
}


type createOrderPayload = {
  preOrderSn: string;
  bookingName: string;
  bookingPhoneArea: string;
  bookingPhone: string;
  bookingEmail: string;
  desc: string;
  flightNumber: string;
  emergencyName: string;
  emergencyPhoneArea: string;
  emergencyMobile: string;
  driverLanguage: string;
};

export function createOrder(payload: createOrderPayload) {
  return request.post('/car/order/createOrder',payload);
}

export function cancelOrder(orderSn: string, formMember: boolean) {
  return request.post('/car/order/cancelOrder', {orderSn,formMember});
}

type orderListPayload = {
  page: number;
  pageSize: number;
};

export function getCarOrdersList(payload: orderListPayload) {
  return request.post('/car/order/orderList', payload);
}

export function getOrderDetail(orderSn: string) {
  return request.post('/car/order/orderDetail', {orderSn});
}

export function applyRefundDetail(orderSn: string) {
  return request.post('/car/order/applyRefundDetail', {orderSn});
}

export function refundOrder(orderSn: string, reason: string) {
  return request.post('/car/order/refundOrder', {orderSn,reason});
}

export function refundDetailInfo(orderSn: string) {
  return request.post('/car/order/refundDetail', {orderSn});
}
